// pages/home2/home2.js

var formutils = require('../../utils/http.js');

const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    _tabIndex: 0,
    list:[],
    month:"",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let date=new Date()
    this.setData({
      month: (date.getMonth()+1)+"月",
    })
    this.LoadData();
  },
  LoadData: function () {
    var that = this //很重要，一定要写
    wx.request({
      url: app.globalData.httpurl + 'v2/record1',
      header: {
        "Authorization": "bearer " + app.globalData.access_token
      },
      data: {
        "page": this.data.page
      },
      method: "GET",
      success: function (res) {
        var datas = res.data.data; //res.data就是从后台接收到的值
        that.setData({
          list: that.data.list.concat(datas),
          loading: false
        })
        wx.stopPullDownRefresh();
      },
      fail: function (res) {
        console.log('submit fail');
      },
      complete: function (res) {
        console.log('submit complete');
      }
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  formhome: function (e) {
    let formid = e.detail.formId
    formutils.postformid(formid)
    wx.redirectTo({
      url: '/pages/home3/home3',
    })
  },
  formkehu: function (e) {
    let formid = e.detail.formId
    formutils.postformid(formid)
    if (app.globalData.isCustomerDistribution) {
      wx.navigateTo({
        url: '/pages/fenpeilist/fenpeilist',
      })
    } else {
      wx.navigateTo({
        url: '/pages/list/listCustom',
      })
    }
  },
  formadd: function (e) {
    let formid = e.detail.formId
    formutils.postformid(formid)
    wx.navigateTo({
      url: '/pages/menu/menus',
    })
  },
  bindList: function (e) {
    var s = e.currentTarget.dataset.id
    this.nabto(4,s)
  },
  bindyesterday:function(e){
    var s = e.currentTarget.dataset.id
    this.nabto(1,s)
  },
  bindweek: function (e) {
    var s = e.currentTarget.dataset.id
   this.nabto(2,s)
  },
  bindmonth: function (e) {
    var s = e.currentTarget.dataset.id
    this.nabto(3,s)
  },
  bindall: function (e) {
    var s = e.currentTarget.dataset.id
    this.nabto(4,s)
  },
  nabto:function(type,id){
    if (app.globalData.isCustomerDistribution) {
      wx.navigateTo({
        url: '/pages/fenpeilist/fenpeilist?type=' + type + "&project_id="+id,
      })
    } else {
      wx.navigateTo({
        url: '/pages/list/listCustom?type=' + type + "&project_id="+id,
      })
    }
  },
  bindxiaofei:function(e){
    var s = e.currentTarget.dataset.id
    var name = e.currentTarget.dataset.name
    wx.navigateTo({
      url: '/tongjiP/pages/tongji/tongji?id=' + s + "&name=" + name,
    })
  },
  bindxfdetails:function(e){
    var s = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/xfdetails/newxf?id='+s,
    })
  }
})